package com.example.room.entity;

import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;

@Entity(tableName = "student")
public class Student {
    //设置主键 id自动增长
    @PrimaryKey(autoGenerate = true)
    //设置数据库表的列信息 名字以及类型
    @ColumnInfo(name = "id", typeAffinity = ColumnInfo.INTEGER)
    public int id;
    @ColumnInfo(name = "name", typeAffinity = ColumnInfo.TEXT)
    public String name;
    @ColumnInfo(name = "age", typeAffinity = ColumnInfo.INTEGER)
    public int age;

    //升级数据库版本2添加的属性
    /*@ColumnInfo(name = "sex", typeAffinity = ColumnInfo.TEXT)
    public int sex;*/

    //升级到版本4 改变其类型为TEXT
    @ColumnInfo(name = "sex", typeAffinity = ColumnInfo.TEXT)
    public String sex;

    @ColumnInfo(name = "bar_data", typeAffinity = ColumnInfo.INTEGER)
    public int barData;


    //ROOM数据库用的构造方法
    public Student(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    //用Ignore注解的变量或者方法不会被ROOM加载
    @Ignore
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Ignore
    public Student(int id) {
        this.id = id;
    }
}
